<?php

/**
 * Framework_Presenter_SmartyRedirect
 *
 * @author Application Support Group
 * @package BAMF
 * @filesource
 */


class Framework_Presenter_SmartyRedirect extends Framework_Presenter_Smarty
{
	
    /**
     * __construct
     *
	 * @author Application Support Group
     * @access public
     * @param mixed $module Instance of Framework_Module
     * @return void
     */
    public function __construct(Framework_Module $module)
    {
        parent::__construct($module);
        
        $this->pageTemplateFile = SMARTY_DEFAULT_REDIRECT_FILE ;
        if( !empty( $module->pageTemplateFile )) {
        	$this->pageTemplateFile = $module->pageTemplateFile ;
        } else {
        	if ( isset( $this->config['default_redirect_tpl'][$this->module->moduleName] ) && !empty( $this->config['default_redirect_tpl'][$this->module->moduleName] )) {
        		$this->pageTemplateFile = $this->config['default_redirect_tpl'][$this->module->moduleName] ;
        	}
        }        
    }

    /**
     * display
     *
     *
	 * @author Application Support Group
     * @return void
     */
    public function display()
    {

		$modulePath = get_class( $this->module ) ;
		$modulePath = str_replace( '_', '/', $modulePath ); 
		$requestedTemplate = SMARTY_TEMPLATE_PATH.$modulePath.'_redirect.tpl' ;
		$modulePath = str_replace( 'Module/', '', $modulePath ) ;
		$tplFile = '' ;

		$this->template->assign( 'modulePath', $modulePath ) ;
		$this->template->assign( 'moduleClass', get_class( $this->module )) ;
		$this->template->assign( 'moduleUuid', $this->module->uuid ) ;

		if (file_exists($requestedTemplate)) {
			$this->template->assign('requestedTemplate', $requestedTemplate) ;
		} else {
			$this->template->assign('originalRequest', $requestedTemplate) ;
			$this->template->assign('requestedTemplate', '') ;			
		}

		foreach ($this->module->getData() as $var => $val) {
			if (!in_array( $var, $this->reservedVariableNames )) {
				$this->template->assign($var,$val);				
			}
		}

		if ( isset( $this->module->itemNumber )) {
			$this->template->assign( 'itemNumber', $this->module->itemNumber ) ;
		}

		$this->template->display($this->pageTemplateFile);

		return true ;


    }

    public function __destruct()
    {
        parent::__destruct();
    }
}

?>
